package mc0429;
import java.util.Scanner;
public class Main {
    static final int N = 5005;
    static final int mod = 998244353;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String s = sc.nextLine();
        long[][] dp = new long[N][N];
        //初始化，[i,i]区间单个字符都算1个回文
        for (int i = 0; i < n; i++) {
            dp[i][i] = 1;
        }
        //字符串长度1...n
        for (int l = 1; l < n; l++) {
        	//递推计算每个长度的区间
            for (int i = 0; i + l < n; i++) {
                int j = i + l;
                //直接用dp递推公式
                if (s.charAt(i) == s.charAt(j)) {
                    dp[i][j] = (dp[i + 1][j] + dp[i][j - 1] + 1) % mod;
                } else {
                    dp[i][j] = (dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1]) % mod;
                }
                //取模运算负数情况处理
                if (dp[i][j] < 0) {
                    dp[i][j] += mod;
                }
            }
        }
        System.out.println(dp[0][n - 1]);
    }
}